<template>
  <div class="NocheckTree">
    <el-input
      placeholder="输入关键字进行过滤"
      size="small"
      v-model="filterText">
    </el-input>

    <el-tree
      style="margin-top: 10px;"
      class="filter-tree"
      :data="data"
      :props="defaultProps"
      :filter-node-method="filterNode"
      :highlight-current="true"
       node-key="id"
       @node-click="handleNodeClick"
      ref="clicktree">
    </el-tree>
  </div>
</template>

<script>
import {getfuandlibianapi} from '@/api/Microgrid/Statistics/MicPerformance'
export default {
  name: 'CallPoliceNocheckTree',

  data() {
    return {
      filterText:'',
      data: [],
      defaultProps: {
         label:'name'
      }
    };
  },

  async mounted() {
    const { data: { list } } = await getfuandlibianapi()
    this.data = list
    this.handleNodeClick(list[0])
    setTimeout(()=>this.$refs.clicktree.setCurrentKey(list[0].id),100)
  },

  methods: {
    handleNodeClick(val) {
      this.$emit('handleNodeClicks',val)
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    }
  },
  watch: {
    filterText(val) {
        this.$refs.tree.filter(val);
    }
  },
};
</script>

<style scoped>
.NocheckTree{
  height: 100%;
  .treebox{
    height: 95%;
    overflow: auto;
  }
}
</style>